package osSRC;

import java.util.InputMismatchException;
import java.util.Scanner;
/**
 * void pause():
 * 		pause the execution of the running process, prompt the user to press ENTER
 * 		and wait until the terminal receives something as input
 * void selectMenu(String choice):
 * 		prints the prompts
 * 		only returns non-negative integers below the number of choices
 *
 */
public class Format {
	public static final int tabSize=4;
	public static void pause(){
		Scanner scanner=new Scanner(System.in);
		System.out.println("Press ENTER to continue");
		scanner.nextLine();
	}
	public static void titleExtend(boolean tab, String title, int end){
		if(tab) System.out.print("\t");
		int tabbed=title.length()/tabSize;
		System.out.print(title+"\t");
		for(int i=tabbed+1;i<end;i++){
			System.out.print("--\t");
		}
	}
	public static void outputDig(int dig){
		System.out.print(dig+"\t");
	}
	public static void outputArray(boolean tab,int[] array){
		if(tab) System.out.print("\t");
		for(int i:array)outputDig(i);
//		System.out.println();
	}
	public static int getInt(String prompt, Scanner scanner){
		while (true){
			try {
				System.out.println(prompt);
				return scanner.nextInt();
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println("Please Enter a NUMBER");
			}
		}
	}
	public static int selectMenu(String[] choices,Scanner scanner){
		int result;

		while (true){
			try {
				for(String choice:choices) System.out.println(choice);
				result= scanner.nextInt();
				if(result>=0&&result<choices.length) {
					return result;
				}
				System.out.println("Please Enter a number between 0-"
						+(choices.length-1)
				);
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println();
			}
		}

	}
}
